package com.hn.birthdaymatch.result;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * @author Ts-SuSu
 * @date 2024/4/27 21:25
 * @description 全局统一返回结果类
*/
@Data
@NoArgsConstructor
@AllArgsConstructor
@ApiModel(value = "全局统一返回结果")
public class Result<T> {

    @ApiModelProperty("响应数据")
    private T datas;

    @ApiModelProperty("响应码")
    private Integer resp_code;

    @ApiModelProperty("响应消息")
    private String resp_msg;

    public boolean isSuccess(){
        return this!=null && this.getResp_code()!=null&&this.getResp_code().intValue()== CodeEnum.SUCCESS.getCode().intValue()?true:false;
    }
    public static <T> Result<T> succeed(String msg) {
        return of(null, CodeEnum.SUCCESS.getCode(), msg);
    }

    public static <T> Result<T> succeed(T model, String msg) {
        return of(model, CodeEnum.SUCCESS.getCode(), msg);
    }

    public static <T> Result<T> succeed(T model) {
        return of(model, CodeEnum.SUCCESS.getCode(), "");
    }

    public static <T> Result<T> of(T datas, Integer code, String msg) {
        return new Result<>(datas, code, msg);
    }

    public static <T> Result<T> failed(String msg) {
        return of(null, CodeEnum.ERROR.getCode(), msg);
    }


    public static <T> Result<T> failed(T model, String msg) {
        return of(model, CodeEnum.ERROR.getCode(), msg);
    }

    }

